package fr.polichouz.geotracer.corelocator.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fr.polichouz.geotracer.corelocator.GeotracerServiceServerImpl;
import fr.polichouz.geotracer.shared.GeotracerService;
import fr.polichouz.geotracer.shared.SimpleLocation;

/**
 * 
 * @author Yoyo
 *
 */
@SuppressWarnings("serial")
public class GetLocationServlet extends HttpServlet {
    
    /** Geotracer service. */
    private GeotracerService service;

    /**
     * Default constructor.
     */
    public GetLocationServlet() {
	super();
	service = GeotracerServiceServerImpl.get();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

	// Get informations
	String username = req.getParameter("username");
	String password = req.getParameter("password");

	// Call the service
	SimpleLocation location = service.getLocation(username, password);

	// Send informations
	if (location != null) {
	    resp.getWriter().println("latittude=" + location.getLattitude());
	    resp.getWriter().println("longitude=" + location.getLongitude());
	}
	
	super.doGet(req, resp);
    }
}
